package top.lcm889.oj.leetcodeTop200;

import java.util.ArrayList;
import java.util.List;
import top.lcm889.oj.databean.TreeNode;

/**
 * @author Coder-lcm
 * @date 2021/4/10
 */
public class LC94_二叉树的中序遍历 {
    List<Integer> res = new ArrayList<>();
    public List<Integer> inorderTraversal(TreeNode root) {
        traverse(root);
        return res;
    }

    public void traverse(TreeNode root) {
        if (root == null) return;
        if (root.left != null) {
            traverse(root.left);
        }
        res.add(root.val);
        if (root.right != null) {
            traverse(root.right);
        }
    }

    public static void main(String[] args) {
        LC94_二叉树的中序遍历 test = new LC94_二叉树的中序遍历();
        TreeNode root = new top.lcm889.oj.databean.TreeNode(23);
        TreeNode left = new top.lcm889.oj.databean.TreeNode(32);
        TreeNode right = new top.lcm889.oj.databean.TreeNode(12);
        root.left = left;
        root.right = right;
        List<Integer> res = test.inorderTraversal(root);
        res.forEach(e -> System.out.println(e + ", "));
    }
}
